<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Register a set of PHP functions as a Lua library</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="luasandbox.pauseusagetimer.html">« LuaSandbox::pauseUsageTimer</a></li>
      <li style="float: right;"><a href="luasandbox.setcpulimit.html">LuaSandbox::setCPULimit »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.luasandbox.html">LuaSandbox</a></li>
    <li>Register a set of PHP functions as a Lua library</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="luasandbox.registerlibrary" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">LuaSandbox::registerLibrary</h1>
  <p class="verinfo">(PECL luasandbox &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">LuaSandbox::registerLibrary</span> &mdash; <span class="dc-title">Register a set of PHP functions as a Lua library</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-luasandbox.registerlibrary-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>LuaSandbox::registerLibrary</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$libname</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$functions</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   Registers a set of PHP functions as a Lua library, so that Lua can call
   the relevant PHP code.
  </p>
  <p class="para">
   For more information about calling Lua functions and the return values,
   see <span class="methodname"><a href="luasandboxfunction.call.html" class="methodname">LuaSandboxFunction::call()</a></span>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-luasandbox.registerlibrary-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">libname</code></dt>

    <dd>

     <p class="para">
      The name of the library. In the Lua state, the global variable of this
      name will be set to the table of functions. If the table already exists,
      the new functions will be added to it.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">functions</code></dt>

    <dd>

     <p class="para">
      An <span class="type">array</span>, where each key is a function name, and each value is a
      corresponding PHP <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-luasandbox.registerlibrary-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-luasandbox.registerlibrary-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3439">
    <p><strong>示例 #1 Registering PHP functions to call from Lua</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;new&nbsp;LuaSandbox<br /></span><span style="color: #0000BB">$sandbox&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">LuaSandbox</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;Register&nbsp;some&nbsp;functions&nbsp;in&nbsp;the&nbsp;Lua&nbsp;environment<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">frobnosticate</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$v&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[&nbsp;</span><span style="color: #0000BB">$v&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">42&nbsp;</span><span style="color: #007700">];<br />}<br /><br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerLibrary</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'php'</span><span style="color: #007700">,&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'frobnosticate'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'frobnosticate'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'output'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;function&nbsp;(&nbsp;</span><span style="color: #0000BB">$string&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$string</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;},<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'error'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;function&nbsp;()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">LuaSandboxRuntimeError</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">"Something&nbsp;is&nbsp;wrong"&nbsp;</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />]&nbsp;);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-luasandbox.registerlibrary-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="luasandbox.loadstring.html" class="methodname" rel="rdfs-seeAlso">LuaSandbox::loadString()</a> - Load Lua code into the Lua environment</span></li>
    <li class="member"><span class="methodname"><a href="luasandbox.wrapphpfunction.html" class="methodname" rel="rdfs-seeAlso">LuaSandbox::wrapPhpFunction()</a> - Wrap a PHP callable in a LuaSandboxFunction</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>